home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / global.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  7KB  |  324 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #define    GLOBAL_DATA
  12. #include "resources.h"
  13. #include "font.h"
  14. #undef    GLOBAL_DATA
  15. #include "const.h"
  16. #include "func.h"
  17. #include "object.h"
  18. #include "paintop.h"
  19.  
  20. /**********************  canvas variables  ************************/
  21.  
  22. int            (*canvas_kbd_proc)();
  23. int            (*canvas_locmove_proc)();
  24. int            (*canvas_leftbut_proc)();
  25. int            (*canvas_middlebut_proc)();
  26. int            (*canvas_rightbut_proc)();
  27. int            fix_x, fix_y;
  28. int            cur_x, cur_y;
  29.  
  30. int            receiving_msg = 0;
  31. int            action_on = 0;
  32. int            pointmarker_shown = 0;
  33. int            compoundbox_shown = 0;
  34.  
  35. int            ICON_COLUMN;
  36. int            CANVAS_HEIGHT, CANVAS_WIDTH;
  37. int            CANVAS_LEFT, CANVAS_TOP;
  38. int            PANEL_LEFT, PANEL_TOP, PANEL_HEIGHT, PANEL_WID;
  39. int            MSG_LEFT, MSG_TOP, MSG_WIDTH;
  40. int            SIDERULER_LEFT, SIDERULER_TOP;
  41. int            SIDERULER_WIDTH, SIDERULER_HEIGHT;
  42. int            SIDERULER_START;
  43. int            TOPRULER_LEFT, TOPRULER_TOP;
  44. int            TOPRULER_WIDTH, TOPRULER_HEIGHT;
  45. int            borderwid, windowspacing, toolstripeht;
  46.  
  47. int            num_point;
  48. F_point            *first_point, *cur_point;
  49.  
  50. /************************  Objects  **********************/
  51.  
  52. /*
  53. Object_tails (not always) point to the last objects in each linked list
  54. in objects.  It is used to speed up an undo-read action.  When a file
  55. is read, the lists of the objects read are stored in saved_objects
  56. and the pointers to tails of the lists in objects would kept in object_tails
  57. the "next" members of the tail objects point to the lists in saved_objects.
  58. To undo, one would only set all the "next" of tail object to NULL;
  59.  
  60. Object_tails is also used for speeding up the undo of compound breaking
  61. action in similar fashion.
  62. */
  63. F_compound        object_tails = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  64. F_compound        objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  65. F_compound        saved_objects = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  66. F_compound        *saved_compound = NULL;    /* Saved the broken compound */
  67.  
  68. /*************************  Undo  variables  **********************/
  69.  
  70. int            last_action = F_NULL;
  71. int            last_object;
  72. int            last_axis;
  73. int            last_rotateangle;
  74. struct {int x, y;}    last_position, new_position;
  75. F_point            *moved_point;
  76. F_point            *deleted_point;
  77. F_point            *added_point;
  78. F_point            *right_point;
  79. int            movedpoint_num;
  80.  
  81. /***************************  Modes  ****************************/
  82.  
  83. int            manhattan_mode        = 0;
  84. int            mountain_mode        = 0;
  85. int            autoforwardarrow_mode    = 0;
  86. int            autobackwardarrow_mode    = 0;
  87. int            latexline_mode        = 0;
  88. int            latexarrow_mode        = 0;
  89. int            magnet_mode        = 0;
  90. int            line_thickness        = 1;
  91. int            pen_size        = 0;
  92. int            pen_type        = 0;
  93. int            flip_axis        = -1;
  94. int            rotate_angle        = 0;
  95. int            cur_line_style        = -1;
  96. float            cur_dashlength        = .05*PIX_PER_INCH;
  97. float            cur_dotgap        = .04*PIX_PER_INCH;
  98. float            cur_styleval        = 0.0;
  99. float            cur_angle        = 0.0;
  100. int            cur_color        = BLACK;
  101. int            cur_textstyle        = PLAIN;
  102.  
  103. short            dot_image[16] = {
  104.                 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  105.                 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  106.                 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  107.                 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
  108.                 };
  109. mpr_static(dot, 16, 16, 1, dot_image);
  110.  
  111. /*************************  Flags  *******************************/
  112.  
  113. int            cur_command = -1;
  114. int            DEBUG = 0;
  115. int            RHS_PANEL = 0;
  116. int            INVERSE = 0;
  117. int            TRACKING = 1;
  118.  
  119. /************************  Status  ****************************/
  120.  
  121. char            directory[128] = "";
  122. char            current_file[32] = "";
  123. int            figure_modified = 0;
  124.  
  125. /************************  Error messages  ****************************/
  126.  
  127. char        Err_incomp[] = "Incomplete %s object at line %d.";
  128. char        Err_mem[] = "Running out of memory.";
  129.  
  130. /************************  Routines  ****************************/
  131.  
  132. null_proc()
  133. {
  134.     }
  135.  
  136. set_modifiedflag()
  137. {
  138.     figure_modified = 1;
  139.     }
  140.  
  141. set_action_on()
  142. {
  143.     action_on = 1;
  144.     }
  145.  
  146. reset_action_on()
  147. {
  148.     action_on = 0;
  149.     }
  150.  
  151. reset_cursor()
  152. {
  153. #ifndef    X11
  154.     win_setcursor(canvas_swfd, cur_cursor);
  155. #else
  156.     XDefineCursor(tool_d, canvas_swfd, (Cursor)cur_cursor->bitmap);
  157. #endif    X11
  158.     }
  159.  
  160. set_temp_cursor(cursor)
  161. CURSOR    cursor;
  162. {
  163. #ifndef    X11
  164.     extern BYTE temporary_cursor;
  165.  
  166.     temporary_cursor = TRUE;
  167.     win_setcursor(canvas_swfd, cursor);
  168.     temporary_cursor = FALSE;
  169. #else
  170.     XDefineCursor(tool_d, canvas_swfd, (Cursor)cursor->bitmap);
  171. #endif    X11
  172.     }
  173.  
  174. set_cursor(cursor)
  175. CURSOR    cursor;
  176. {
  177.     cur_cursor = cursor;
  178. #ifndef    X11
  179.     win_setcursor(canvas_swfd, cursor);
  180. #else
  181.     XDefineCursor(tool_d, canvas_swfd, (Cursor)cursor->bitmap);
  182. #endif    X11
  183.     }
  184.  
  185. set_lastaxis(a)
  186. int    a;
  187. {
  188.     last_axis = a;
  189.     }
  190.  
  191. set_lastangle(a)
  192. int    a;
  193. {
  194.     last_rotateangle = a;
  195.     }
  196.  
  197. set_lastposition(x, y)
  198. int    x, y;
  199. {
  200.     last_position.x = x;
  201.     last_position.y = y;
  202.     }
  203.  
  204. set_action(action)
  205. int     action;
  206. {
  207.     last_action = action;
  208.     }
  209.  
  210. set_action_object(action, object)
  211. int     action, object;
  212. {
  213.     last_action = action;
  214.     last_object = object;
  215.     }
  216.  
  217. /*
  218. Clean_up should be called before committing a user's request.
  219. Clean_up will attempt to free all the allocated memories which
  220. resulted from delete/remove action.  It will set the last_action
  221. to F_NULL.  Thus this routine should be before set_action_object().
  222. if they are to be called in the same routine.
  223. */
  224. clean_up()
  225. {
  226.     if (last_action == F_REMOVE) {
  227.         switch (last_object) {
  228.         case O_ARC :
  229.             free_arc(&saved_objects.arcs);
  230.             break;
  231.         case O_COMPOUND :
  232.             free_compound(&saved_objects.compounds);
  233.             break;
  234.         case O_ELLIPSE :
  235.             free_ellipse(&saved_objects.ellipses);
  236.             break;
  237.         case O_POLYLINE :
  238.             free_line(&saved_objects.lines);
  239.             break;
  240.         case O_SPLINE :
  241.             free_spline(&saved_objects.splines);
  242.             break;
  243.         case O_TEXT :
  244.             free_text(&saved_objects.texts);
  245.             break;
  246.         case O_ALL_OBJECT :
  247.             free_arc(&saved_objects.arcs);
  248.             free_compound(&saved_objects.compounds);
  249.             free_ellipse(&saved_objects.ellipses);
  250.             free_line(&saved_objects.lines);
  251.             free_spline(&saved_objects.splines);
  252.             free_text(&saved_objects.texts);
  253.             break;
  254.         }
  255.         }
  256.     else if (last_action == F_DELETE_POINT) {
  257.         free((char*)deleted_point);
  258.         }
  259.     else if (last_action == F_REMOVE_ALL || last_action == F_EDIT) {
  260.         free_arc(&saved_objects.arcs);
  261.         free_compound(&saved_objects.compounds);
  262.         free_ellipse(&saved_objects.ellipses);
  263.         free_line(&saved_objects.lines);
  264.         free_spline(&saved_objects.splines);
  265.         free_text(&saved_objects.texts);
  266.         }
  267.     else if (last_action == F_BREAK) {
  268.         free_compound(&saved_compound);
  269.         }
  270.     else if (last_action == F_CREATE) {
  271.         saved_objects.arcs = NULL;
  272.         saved_objects.compounds = NULL;
  273.         saved_objects.ellipses = NULL;
  274.         saved_objects.lines = NULL;
  275.         saved_objects.splines = NULL;
  276.         saved_objects.texts = NULL;
  277.         }
  278.     else if (last_action == F_TURN) {
  279.         if (last_object == O_POLYLINE) {
  280.         free_line(&saved_objects.lines);
  281.         }
  282.         else {    /* last_object == O_SPLINE */
  283.         free_spline(&saved_objects.splines);
  284.         }
  285.         }
  286.     last_action = F_NULL;
  287.     }
  288.  
  289. set_latestarc(arc)
  290. F_arc    *arc;
  291. {
  292.     saved_objects.arcs = arc;
  293.     }
  294.  
  295. set_latestcompound(compound)
  296. F_compound    *compound;
  297. {
  298.     saved_objects.compounds = compound;
  299.     }
  300.  
  301. set_latestellipse(ellipse)
  302. F_ellipse    *ellipse;
  303. {
  304.     saved_objects.ellipses = ellipse;
  305.     }
  306.  
  307. set_latestline(line)
  308. F_line    *line;
  309. {
  310.     saved_objects.lines = line;
  311.     }
  312.  
  313. set_latestspline(spline)
  314. F_spline    *spline;
  315. {
  316.     saved_objects.splines = spline;
  317.     }
  318.  
  319. set_latesttext(text)
  320. F_text    *text;
  321. {
  322.     saved_objects.texts = text;
  323.     }
  324.